;
; Author: Javier Quevedo Fernandez
;
; This program is free software; you can redistribute it and/or modify
; it under the terms of the GNU General Public License as published by
; the Free Software Foundation; either version 2 of the License, or
; (at your option) any later version.
;
; This program is distributed in the hope that it will be useful,
; but WITHOUT ANY WARRANTY; without even the implied warranty of
; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
; GNU General Public License for more details.
;
; You should have received a copy of the GNU General Public License
; along with this program; if not, write to the Free Software
; Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA

;; -------------------------------------------------------------
;; -------------------------------------------------------------
;;						GESTOR DE MOTORES
;; -------------------------------------------------------------
;; -------------------------------------------------------------

org	1580h
MOTOR_INIT:
	
	LCALL	EJECUTAR_IM1P
	LCALL	EJECUTAR_IM2P
	RET

; Delays 255 us

DELAY_PIC:
	PUSH	ACC
	MOV	A,#255
	DJNZ	ACC,$
	POP	ACC
	RET

EJECUTAR_IM1I:
	CLR 	MEN	
	CLR	M1	
	CLR	M2
	CLR	M3	
	CLR	D1	
	CLR	D2
	NOP
	NOP
		
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC
RET

	;MOTOR 1 = DERECHA
EJECUTAR_IM1D:
	CLR 	MEN	
	CLR	M1	
	CLR	M2
	CLR	M3	
	SETB	D1	
	CLR	D2
	NOP
	NOP	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC
RET
	;MOTOR 1 = PARADO
EJECUTAR_IM1P:
	CLR 	MEN	
	CLR	M1	
	CLR	M2
	CLR	M3	
	CLR	D1	
	SETB	D2
	NOP
	NOP	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC

RET
	;MOTOR 2 = IZQUIERDA
EJECUTAR_IM2I:
	CLR 	MEN	
	SETB	M1	
	CLR	M2
	CLR	M3	
	CLR	D1	
	CLR	D2	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC
RET

	;MOTOR 2 = DERECHA
EJECUTAR_IM2D:
	CLR 	MEN	
	SETB	M1	
	CLR	M2
	CLR	M3	
	SETB	D1	
	CLR	D2	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC

RET
	;MOTOR 2 = PARADO
EJECUTAR_IM2P:
	CLR 	MEN	
	SETB	M1	
	CLR	M2
	CLR	M3	
	CLR	D1	
	SETB	D2	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC
RET

	;MOTOR 3 = IZQUIERDA
EJECUTAR_IM3I:
	CLR 	MEN	
	CLR	M1	
	SETB	M2
	CLR	M3	
	CLR	D1	
	CLR	D2	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC
RET

	;MOTOR 3 = DERECHA
EJECUTAR_IM3D:
	CLR 	MEN	
	CLR	M1	
	SETB	M2
	CLR	M3	
	SETB	D1	
	CLR	D2
	NOP
	NOP	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC
RET
	
	;MOTOR 1 = PARADO
EJECUTAR_IM3P:
	CLR 	MEN	
	CLR	M1	
	SETB	M2
	CLR	M3	
	CLR	D1	
	SETB	D2
	NOP
	NOP	
	SETB	MEN
	CLR	MEN
	LCALL	DELAY_PIC

RET
	

EJECUTAR_AVANZAR:
	LCALL	EJECUTAR_IM2D
	LCALL	EJECUTAR_IM1I
RET


EJECUTAR_PARAR:
	LCALL	EJECUTAR_IM2P
	LCALL	EJECUTAR_IM1P
RET

EJECUTAR_RETROCEDER:
	LCALL	EJECUTAR_IM2I
	LCALL	EJECUTAR_IM1D
RET
	
EJECUTAR_GIRAR_IZQUIERDA:
	LCALL	EJECUTAR_IM2D
	LCALL	EJECUTAR_IM1P
RET

EJECUTAR_GIRAR_DERECHA:
	LCALL	EJECUTAR_IM2P
	LCALL	EJECUTAR_IM1I
RET

	
EJECUTAR_SENSOR_CENTRO:
	LCALL	EJECUTAR_IM3P
	RET

EJECUTAR_SENSOR_DERECHA:
	LCALL	EJECUTAR_IM3D
	RET

EJECUTAR_SENSOR_IZQUIERDA:	
	LCALL	EJECUTAR_IM3I
	RET
	